package com.guigu.community.controller;

import com.guigu.community.pojo.ProductCategory;
import com.guigu.community.service.ProductCategoryService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    //查询出所有分类列表
    @PostMapping("listProductCategory")
    @ResponseBody
    public List<ProductCategory> listProductCategory(){
        return productCategoryService.queryProductCategory();
    }

//    增加
    @PostMapping("addProductCategory")
    public String  addProductCategory(@RequestBody ProductCategory productCategory){
        boolean save = productCategoryService.save(productCategory);
        if (save)
            return "yes";
        return "no";
    }

    //修改
    @PostMapping("updateProductCategory")
    public String  updateProductCategory(@RequestBody ProductCategory productCategory){
        boolean update = productCategoryService.updateById(productCategory);
        if (update)
            return "yes";
        return "no";
    }

    //删除
    @DeleteMapping("deleteProductCategory/{pcid}")
    public String deleteProductCategory(@PathVariable Integer pcid){
        boolean b = productCategoryService.removeById(pcid);
        if (b)
            return "yes";
        return "no";
    }
}
